﻿using System;
namespace AzureStorageMapper.TableStorage.ActionModes
{
    public enum SaveMode
    {
        Insert,
        InsertOrReplace,
        InsertOrMerge
    }

    public enum UpdateMode
    {
        Update,
        Merge
    }

    public class ActionModeToHttpMethod
    {
        public static string Convert(SaveMode mode)
        {
            string method;
            switch (mode)
            {
                case SaveMode.Insert:
                    method = "POST";
                    break;
                case SaveMode.InsertOrReplace:
                    method = "PUT";
                    break;
                case SaveMode.InsertOrMerge:
                    method = "MERGE";
                    break;
                default:
                    throw new NotSupportedException(string.Format("Invalid SaveMode: '{0}'", mode));
            }
            return method;
        }

        public static string Convert(UpdateMode mode)
        {
            string method;
            switch (mode)
            {
                case UpdateMode.Update:
                    method = "PUT";
                    break;
                case UpdateMode.Merge:
                    method = "MERGE";
                    break;
                default:
                    throw new NotSupportedException(string.Format("Invalid UpdateMode: '{0}'", mode));
            }
            return method;
        }
    }
}
